package cn.schoolwow.util.test.module.query.jsonarray.flow.query;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.domain.query.jsonarray.QueryJSONArray;
import com.alibaba.fastjson.JSONArray;
import org.junit.Assert;

import java.util.ArrayList;
import java.util.List;

public class JSONQueryNotInQueryFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        JSONArray userArray = (JSONArray) flowContext.checkData("userArray");

        List<String> usernameQueryList = new ArrayList<>();
        for(int i=0;i<5;i++){
            usernameQueryList.add("username"+i);
        }

        List<String> usernameList = QueryJSONArray.newQuery(userArray)
                .addNotInQuery("username", usernameQueryList)
                .execute()
                .getSingleFieldValueList("username");
        Assert.assertEquals(5,usernameList.size());
        for(int i=5;i<10;i++){
            Assert.assertTrue(usernameList.contains("username"+i));
        }
    }

    @Override
    public String name() {
        return "用户JSON列表查询-notInQuery查询";
    }
}
